package com.zcx.qshop.conn;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;
import com.zcx.qshop.entity.Good;

@HttpInlet(Conn.INLET_JSON_SERCHLIST)
public class JsonSerchlistAsyGet extends QSAsyGet<JsonSerchlistAsyGet.Info> {
	
	public String keyword, areaid, schoolid;

	public JsonSerchlistAsyGet(String keyword, String areaid, String schoolid, AsyCallBack<Info> asyCallBack) {

		super(asyCallBack);

		this.keyword = keyword;

		this.areaid = areaid;

		this.schoolid = schoolid;

	}
	
	@Override
	public Info parser(JSONObject object) {

		if(object.optString("message").equals("1")){
			
			Info info = new Info();
			
			JSONArray array = object.optJSONArray("serchslist");
			
			for (int i = 0; i < array.length(); i++) {
				
				Good good = new Good();
				
				JSONObject o = array.optJSONObject(i);
				
				good.pid = o.optString("gid");
				
				good.picurl = Conn.SERVICE + o.optString("picurl");
				
				good.title = o.optString("title");  
				
				good.price = o.optString("price");
				
				good.unit = o.optString("unit");

				good.number = o.optString("number");
				
				info.goods.add(good);
				
			}
			
			return info;
			
		}
		
		return null;
		
	}

	public static class Info implements Serializable{
		
		public List<Good> goods = new ArrayList<Good>();
		
	}
	
}
